﻿@{
    ViewBag.Title = "UpdateCarInsurance";
    ViewBag.First = "车辆管理";
    ViewBag.Second = "修改保险记录";
    Layout = "~/Views/Shared/_BaseLayout.cshtml";

    var ent = ViewData["ent"] as Sc.Domain.Car_Insurance;
    var list = ViewData["type"] as IList<Sc.Domain.BaseItem>;
}
<script src="~/Content/laydate-v1.1/laydate/laydate.js"></script>
<script type="text/javascript">
    $(document).ready(function (e) {
        initSingleDate("txtBeginTime", "YYYY/MM/DD");
        initSingleDate("txtEndTime", "YYYY/MM/DD");

        $(".select2").uedSelect({
            width: 110
        });
    });
    //车辆选择
    function selectCar() {
        layer.open({
            type: 2,
            title: "车辆选择",
            shade: [0],
            area: [($(window).width() - 20) + "px", ($(window).height() - 80) + "px"],
            content: ['@Url.Action("SelectCarInfo", "CarInfo")', 'yes']
        });
    }
    //车辆选择确认
    function sureCarInfo(id, carNo) {
        var car = $("#txtCar");
        car.val(carNo); car.attr("carId", id);
        layer.closeAll();
    }

    //数据保存
    function saveData(tag) {
        var txtCar = $("#txtCar").val();
        var txtInsuranceNo = $("#txtInsuranceNo").val();
        var txtInsuranceMoney = $("#txtInsuranceMoney").val();
        var txtInsuranceCompany = $("#txtInsuranceCompany").val();
        var txtBeginTime = $("#txtBeginTime").val();
        var txtEndTime = $("#txtEndTime").val();

        if (txtCar.length <= 0) {
            Tips("请选择要被保险的车辆", "txtCar");
            return false;
        }
        if (txtInsuranceNo.length <= 0) {
            Tips("保险单号不能为空", "txtInsuranceNo");
            return false;
        }
        if (txtInsuranceMoney.length <= 0) {
            Tips("保险金额不能为空", "txtInsuranceMoney");
            return false;
        }
        if (txtInsuranceCompany.length <= 0) {
            Tips("保险公司不能为空", "txtInsuranceConpany");
            return false;
        }
        if (txtBeginTime.length <= 0) {
            Tips("购买保险时间不能为空", "txtBeginTime");
            return false;
        }
        if (txtEndTime.length <= 0) {
            Tips("保险到期时间不能为空", "txtEndTime");
            return false;
        }

        var ent = new Object();
        ent.CarId = $("#txtCar").attr("carId");
        ent.TypeId = $("#selType").val();
        ent.InsuranceNo = txtInsuranceNo;
        ent.InsuranceMoney = txtInsuranceMoney;
        ent.InsuranceCompany = txtInsuranceCompany;
        ent.BeginTime = txtBeginTime;
        ent.EndTime = txtEndTime;
        ent.id = '@ent.Id';
        var url = "@Url.Action("SaveData")";
        var load = loadTip("数据提交中，请稍候", 16, 0);
        $.post(url, { data: JSON.stringify(ent), id: '@ent.Id' }, function (data) {
            if (data > 0) {
                if (tag == 1) {
                    layer.msg("数据保存成功", { icon: 1, time: 1000, shade: [0.3, '#000'] }, function () {
                        document.getElementById("svForm").reset();
                    });
                } else {
                    layer.msg("数据保存成功", { icon: 1, time: 1000, shade: [0.3, '#000'] }, function () {
                        back();
                    });
                }
            }
        });
    }
    function back() {
        window.location.href = "@Url.Action("Index")";
    }
</script>
<div class="formbody">
    <div class="formtitle"><span>创建保险登记</span></div>
    <form id="svForm">
        <ul class="forminfo">
            <li>
                <label>被保险车辆</label><input type="text" class="dfinput" id="txtCar" value="@ent.CarNo" carId="@ent.CarId" />
                <input type="button" style="width:80px;margin-left:10px" class="btn" onclick="selectCar();" value="选择" />
            </li>
            <li>
                <label>保险类型</label><div class="vocation">
                    <select name="select" class="select2" id="selType">
                        @if (list != null)
                        {
                            foreach (var item in list)
                            {
                                <option @(ent.TypeId == item.Id ? "selected" : "") value="@item.Id">@item.Name</option>
                            }
                        }
                    </select>
                </div>
            </li>
            <li><label>保险单号</label><input type="text" class="dfinput" id="txtInsuranceNo" value="@ent.InsuranceNo" /></li>
            <li><label>保险金额</label><input type="text" class="dfinput" id="txtInsuranceMoney" value="@ent.InsuranceMoney" /></li>
            <li><label>保险公司</label><input class="dfinput" id="txtInsuranceCompany" value="@ent.InsuranceCompany" /></li>
            <li><label>保险购买时间</label><input class="dfinput" id="txtBeginTime" value="@ent.BeginTime" /></li>
            <li><label>保险到期时间</label><input class="dfinput" id="txtEndTime" value="@ent.EndTime" /></li>
            <li>
                <label>&nbsp;</label>
                <input type="button" class="btn" onclick="saveData(1);" value="保存继续" />
                <input type="button" class="btn" onclick="saveData(2);" value="保存退出" />
                <input type="button" class="btn" onclick="back();" value="返 回" />
            </li>
        </ul>
    </form>
</div>
